
//
//  HWHeaderView.m
//  94hwan
//
//  Created by 金石 on 2018/5/3.
//  Copyright © 2018年 孔祥刚. All rights reserved.
//

#import "HWHeaderView.h"

@interface HWHeaderView()

@property (strong,nonatomic) UIButton *rightButton;
@end

@implementation HWHeaderView

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.userInteractionEnabled = YES;
      //   self.image = [UIImage imageNamed:@"headerBackgroud.png"];
       
        [self setupViews];
    }
    return self;
}

- (void)setupViews {
    self.leftButton = [self getLeftButton];
    [self addSubview:self.leftButton];
    
    self.title = [UILabel new];
    self.title.textColor = [UIColor whiteColor];
    self.title.textAlignment = NSTextAlignmentCenter;
    [self addSubview:self.title];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if (self.leftButton) {
        [self.leftButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.height.and.width.mas_equalTo(self.mas_height).dividedBy(2.5);
            make.left.mas_equalTo(self.mas_left).offset(14);
            make.bottom.mas_equalTo(self.mas_bottom).offset(-10);
        }];
    }
    [self.title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.height.mas_equalTo(self.leftButton.mas_height);
        make.left.mas_equalTo(40);
        make.right.mas_equalTo(-40);
        make.centerY.mas_equalTo(self.leftButton.mas_centerY);
    }];
}



#pragma mark - 懒加载
- (UIButton *)getLeftButton {
    if (self.leftButton == nil) {
        self.leftButton = [UIButton new];
        [self.leftButton addTarget:self action:@selector(clickLeftButton:) forControlEvents:UIControlEventTouchUpInside];
        [self.leftButton setImage:[UIImage imageNamed:@"fanhui"] forState:UIControlStateNormal];
    }
    return self.leftButton;
}

- (UILabel *)getTitle {
    if (self.title == nil) {
        self.title = [UILabel new];
    }
    return self.title;
}

#pragma mark - 点击了左边的按钮

- (void)clickLeftButton:(UIButton *)sender {
    if (self.leftClick) {
        self.leftClick();
    }
}

/*
 // Only override drawRect: if you perform custom drawing.
 // An empty implementation adversely affects performance during animation.
 - (void)drawRect:(CGRect)rect {
 // Drawing code
 }
 */

@end
